//
//  RootViewController.m
//  OurRelax
//
//  Created by 于宾尧 on 15/6/16.
//  Copyright (c) 2015年 于宾尧. All rights reserved.
//

#import "RootViewController.h"

#import "MusicDetailViewController.h"

@interface RootViewController ()

@property (nonatomic, retain) CHDViewController *chd;

@end

@implementation RootViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self subMyViews];
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBarHidden = YES;
    
    //前景
    if (![TagHandle shareTagHandle].isFirst) {
        
        UIImage *image = [UIImage imageNamed:@"preLandscape.jpg"];
        UIImageView *preImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, self.view.frame.size.height)];
        preImageView.image = image;
        [self.view addSubview:preImageView];
        
        [UIView animateWithDuration:6 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            
            [preImageView setFrame:CGRectMake(-image.size.width + self.view.frame.size.width, 0, image.size.width, self.view.frame.size.height)];
            
        } completion:^(BOOL finished) {
            
            [preImageView setFrame:CGRectZero];
            
            //保证只走一次
            [TagHandle shareTagHandle].isFirst = YES;
            
        }];
        
    }
    
    //状态栏
    if ([MusicDetailShareHandle shareListDataHandle].statusMusic != nil) {
        
        _chd.titleL.text = [MusicDetailShareHandle shareListDataHandle].statusMusic.song_name;
        _chd.subTitleL.text = [MusicDetailShareHandle shareListDataHandle].statusMusic.singer_name;
        
        NSMutableArray *durationArray = (NSMutableArray *)[MusicDetailShareHandle shareListDataHandle].statusMusic.url_list;
        NSMutableDictionary *durationDic = [durationArray firstObject];
        NSString *durationStr = [NSString stringWithFormat:@"00:00 - %@", [durationDic objectForKey:@"duration"]];
        _chd.duringL.text = durationStr;
    }
    
    //播放栏
    if ([TagHandle shareTagHandle].isPlaying) {
        
        [_chd.playButton setBackgroundImage:[UIImage imageNamed:@"play_bar_pause.png"] forState:UIControlStateNormal];
        
    } else {
        
        [_chd.playButton setBackgroundImage:[UIImage imageNamed:@"play_bar_play.png"] forState:UIControlStateNormal];
    }
}

-(void)subMyViews
{
    //    CHDViewController是三方,用来实现三个页面之间滑动的
    self.chd = [[CHDViewController alloc]init];
    
    //    把三个页面的title放到一个数组里
    NSArray *titleArray = @[@"乐库",@"电台",@"资讯"];
    
    MusicViewController *musicVC = [[MusicViewController alloc]init];
    musicVC.myDelegate = self;
    RadioViewController *radioVC = [[RadioViewController alloc]init];
#pragma 改动
    radioVC.myDelegate = self;
    radioVC.radioCellVC.myDelegate = self;
    NewsViewController *newsVC = [[NewsViewController alloc]init];
    
    musicVC.theTitle = titleArray[0];
    radioVC.theTitle = titleArray[1];
    newsVC.theTitle = titleArray[2];
    
    [_chd.ScrollControllersArr addObject:musicVC];
    [_chd.ScrollControllersArr addObject:radioVC];
    [_chd.ScrollControllersArr addObject:newsVC];
    
    _chd.nameArr = [NSMutableArray arrayWithArray:titleArray];
    
    _chd.myDelegation = self;
    
    [self.view addSubview:_chd.view];
    //[self presentViewController:chd animated:YES completion:nil];
    
}

#pragma 签协议

-(void)pushToWords11
{
    
    NSLog(@"1111111111111");
    WordsViewController *wordsVC = [[WordsViewController alloc]init];
    //   UINavigationController *wordC = [UINavigationController alloc]initWithRootViewController:wordsVC
    self.navigationController.navigationBarHidden = NO;
    
    
    [self.navigationController pushViewController:wordsVC animated:YES];

    
}
-(void)pushToWords
{
    WordsViewController *wordsVC = [[WordsViewController alloc]init];
//   UINavigationController *wordC = [UINavigationController alloc]initWithRootViewController:wordsVC
    self.navigationController.navigationBarHidden = NO;

    
    [self.navigationController pushViewController:wordsVC animated:YES];
}

-(void)presentTo
{
    [self.navigationController presentLeftMenuViewController:self];
}

#pragma 实现push到下一页
-(void)pushToDetail:(NSString *)barTitle andArray:(NSMutableArray *)songListArray andDetailModel:(MusicDetailModel *)musicDetail
{
    MusicDetailViewController *musicDetailVC = [[MusicDetailViewController alloc] init];
    
    self.navigationController.navigationBarHidden = NO;
    musicDetailVC.titleStr = barTitle;
    musicDetailVC.mySonglistArray = songListArray;
    musicDetailVC.myMusicDetail = musicDetail;
    musicDetailVC.detailSonglist = [MusicDetailShareHandle shareListDataHandle].statusMusic;
    //NSLog(@"%@",musicDetail.pics);
    [self.navigationController pushViewController:musicDetailVC animated:YES];
}

-(void)pushToDetail
{
    MusicDetailViewController *musicDetailVC = [[MusicDetailViewController alloc] init];
    
    self.navigationController.navigationBarHidden = NO;
    //self.navigationController.navigationBar.translucent = NO;
    [self.navigationController pushViewController:musicDetailVC animated:YES];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
